package lapsnake.model.stmt;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for While nodes*/
public class LapWhile extends LapStatement {
	public final SingleChild<LapExpression> test = new SingleChild<>(this, LapExpression.class);
	@NewRow public final ChildList<LapStatement> body = new ChildList<>(this, LapStatement.class, false);
	@NewRow public final ChildList<LapStatement> orelse = new ChildList<>(this, LapStatement.class, true);

	public LapWhile(PyAST pyAST, ChildField<? super LapWhile> parent, While node) throws PropertyVetoException {
		super(pyAST, parent, node);
		
		ASTHelperFactory.makeHelper(pyAST, test, node.getInternalTest());
		ASTHelperFactory.makeHelpers(pyAST, body, node.getInternalBody());
		ASTHelperFactory.makeHelpers(pyAST, orelse, node.getInternalOrelse());
		
		buildTextNodes(node);
	}
	
	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{
		if(childField == test)
			return new JTreeLabel("While", false);
		else if(childField == body)
			return new JTreeLabel("Do:", true);
		else
			return new JTreeLabel("Else:", true);
	}
}
